package com.bbx.taxi.client.Task;

import java.util.List;

import android.app.Activity;

import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.utils.DistanceUtil;
import com.bbx.androidapi.util.SystemUtil;
import com.bbx.androidapi.util.ToastUtil;
import com.bbx.api.sdk.model.passanger.CarTypeBuild;
import com.bbx.api.sdk.model.passanger.MeteredFeeBuild;
import com.bbx.api.sdk.model.passanger.Return.CarType.CarData;
import com.bbx.api.sdk.model.passanger.Return.CarType.CarType;
import com.bbx.api.sdk.model.passanger.Return.MyOrderList.Location;
import com.bbx.api.sdk.net.base.BaseNetwork;
import com.bbx.api.sdk.net.passeger.conn.CarTypeNet;
import com.bbx.api.sdk.net.passeger.conn.MeteredFeeNet;
import com.bbx.taxi.client.MyApplication;
import com.bbx.taxi.client.Activity.Main.MainActivity;
import com.bbx.taxi.client.Bean.Value;
import com.bbx.taxi.client.Bean.Attribute.MainAttribute;
import com.bbx.taxi.client.Bean.Attribute.MainAttribute.CjType;
import com.bbx.taxi.client.Bean.Message.ObserverListener.DATA_TYPE;
import com.bbx.taxi.client.Util.DateFormat;

/**
 * @Path com.bbx.taxi.client.Task.MyMeteredFee.java
 * @Author 严旭文
 * @Date 2016-9-30 上午9:22:45
 * @Company 蓝海（福建）信息技术有限公司
 * @Description
 */
public class MyMeteredFeeTask extends BaseTask {
	public DATA_TYPE TYPE = DATA_TYPE.METEREDFEE;
	private MeteredFeeBuild mMeteredFeeBuild;
	/** 用于判断是否是当前的类型，城际，市内，快件 */
	private int view_id;
	/** 判断拼车，包车，顺风车 */
	private CjType citype;
	/**
	 * @param context
	 * @param line_id
	 * @param data
	 * @param ll
	 * @param type   同订单类型 1－包车 3－市内  MyCarTypeTask类有写
	 */
	public MyMeteredFeeTask(Activity context,CarData data,int type,int distance,int view_id,
			CjType citype) {
		super(context);
		this.view_id = view_id;
		this.citype = citype;
		MyApplication mApplication=MyApplication.getInstance();
		mMeteredFeeBuild=new MeteredFeeBuild(context);
		mMeteredFeeBuild.uid=mApplication.getUid();
		mMeteredFeeBuild.access_token=mApplication.getToken();
		mMeteredFeeBuild.line_id=data.line_id;
		mMeteredFeeBuild.car_level=data.car_level;
		mMeteredFeeBuild.car_type=data.car_type;
		mMeteredFeeBuild.car_seats=data.car_seats;
		mMeteredFeeBuild.type=type;
		mMeteredFeeBuild.price_id=data.price_id;
		mMeteredFeeBuild.car_class_id=data.car_class_id;
//		//注意不要使用data.business_type，要用id  
//		if(id>=0){
//			mMeteredFeeBuild.business_type=id;
//		}else{	
//			mMeteredFeeBuild.business_type=data.business_type;
//		}
		mMeteredFeeBuild.business_type=data.business_type;
		mMeteredFeeBuild.calc_type=data.calc_type;
		mMeteredFeeBuild.miles=distance;
		mMeteredFeeBuild.start_time=DateFormat.onDate_Long(MainAttribute.getInstance().getTime(view_id==Value.VIEWID_SN))/1000;
		//当前位置
		LatLng ll= new LatLng(mApplication.latitude,mApplication.longitude);
		mMeteredFeeBuild.location=new Location(ll.longitude,ll.latitude);
		mMeteredFeeBuild.version=SystemUtil.getAppVersionName(context);
		
		MainAttribute main=MainAttribute.getInstance();
		mMeteredFeeBuild.appoint_time=DateFormat.onDateAdd_ss(main
				.getTime(view_id==Value.VIEWID_SN));// 预约时间
	}

	@Override
	public boolean isShow() {
		return true;
	}

	@Override
	public boolean isReturnString() {
		return false;
	}
	@Override
	public boolean condition() {
		try {
			MainActivity mainactivity = (MainActivity) context;
			MainAttribute main = MainAttribute.getInstance();
			if (mainactivity.mPresenter.getViewId() == view_id
					&& main.getCjType() == citype) {
				return true;
			} else {
				return false;
			}
		} catch (Exception e) {

			return true;
		}
	}
	@Override
	public void request() {
		setType(TYPE, mMeteredFeeBuild);
	}

	@Override
	public void success(int status,Object object) {
		// TODO Auto-generated method stub

	}

	@Override
	public void failed(int status, String msg,String message) {
		ToastUtil.showToast(context, message);
	}

	@Override
	public BaseNetwork getBaseNetwork() {
		return new MeteredFeeNet(context);
	}
}
